package com.dk.service.brand;

import com.alibaba.dubbo.config.annotation.Service;
import com.dk.mapper.brand.TbBrandMapper;
import com.dk.page.Page;
import com.dk.pojo.brand.TbBrand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
@Service
@Component
public class BrandServiceImpl implements BrandService {
    @Resource
    private TbBrandMapper brandMapper;

    @Override
    public List<TbBrand> listBrand() {
        return brandMapper.selectByExample(null);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @Override
    public int deleteBrandByIds(Long[] ids) {
        return brandMapper.deleteBrandByIds(ids);
    }

    /***
     * 根据id修改brand
     * @param tbBrand
     * @return
     */
    @Override
    public int updateBrandById(TbBrand tbBrand) {
        return brandMapper.updateByPrimaryKeySelective(tbBrand);
    }

    /**
     * 根据id查询brand
     * @param id
     * @return
     */
    @Override
    public TbBrand getBrandById(Long id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    /**
     * 品盘添加
     * @param tbBrand
     * @return
     */
    @Override
    public int addBrand(TbBrand tbBrand) {

        return brandMapper.insertSelective(tbBrand);
    }

    /**
     *获取数据并分页
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @Override
    public Page getListBrand(Integer pageNumber, Integer pageSize) {
        // 分页插件分页
        PageHelper.startPage(pageNumber,pageSize);
        // 获取记录
        List<TbBrand> brandList = brandMapper.selectByExample(null);
        // 获取pageInfo
        PageInfo<TbBrand> pageInfo = new PageInfo<>(brandList);
        // 创建工具类
        Page page = new Page();
        page.setTotal(pageInfo.getTotal());
        page.setRows(pageInfo.getList());
        return page;
    }
}
